<?php $this->load->helper('HTML');
echo link_tag('css/style2.css');
echo link_tag('images/favicon.ico','shortcut icon','image/x-icon');
?>
<div id="page1">
<?php $this->load->view('admin_views/header'); ?>
</head>

<div id="wrapper">
<script type="text/javascript">
    $(document).ready( function() {
        $("#konfirm1").dialog({
		autoOpen: false,
		modal: true
	});

    $("#informasi").dialog({
		autoOpen: false,
		modal: true,
		width: '300'
	});
	
    $("#intid_unit").autocomplete({
                    minLength: 2,
                    source:
                        function(req, add){
                        $.ajax({
                            url: "<?php echo base_url(); ?>penjualan/lookupUnit",
                            dataType: 'json',
                            type: 'POST',
                            data: req,
                            success:
                                function(data){
                                if(data.response =="true"){
                                    add(data.message);
                                }
                            },
                        });
                    },
                    focus:function(event,ui){var q=$(this).val();$(this).val()=q;},select:
                        function(event, ui) {
                        $("#result2").append(
                        "<input type='hidden' id='id_unit' name='id_unit' value='" + ui.item.id + "' size='10' />"
                    );
                    },
                });


        $("#strnama_dealer").autocomplete({
            minLength: 1,
            source:
                function(req, add){
                $.ajax({
                    url: "<?php echo base_url(); ?>penjualan/lookupUplineCalon",
                    dataType: 'json',
                    type: 'POST',
                    data: {
                     term: req.term,
                     state: $('#id_unit').val(),
                    },
                    success:
                        function(data){
                        if(data.response =="true"){
                            add(data.message);
                        }
                    },
                });
            },
            focus:function(event,ui){var q=$(this).val();$(this).val()=q;},select:
                function(event, ui) {
                        $("#result").append(
                        "<input type='text' align='top' id='strkode_dealer' name='strkode_dealer' value='" + ui.item.id + "'/><br><td><input type='text' id='strkode_upline' name='strkode_upline' value='" + ui.item.value2 + "'/></td>"
                    );
            },
        });

        
    });

    function breakdown(){
        
	var form = $('#sr_from');
    var strkode_dealer = $("#strkode_dealer").val();
    var strkode_upline = $("#strkode_dealer").val();
    var id_unit = $("#id_unit").val();
    var unit_baru = $("#unit_baru").val();

	$("#konfirm1").html('');
	$("#konfirm1").html("Are You Sure To Breakdown This Dealer??");
	$('#konfirm1').dialog('option','width',450);
	$('#konfirm1').dialog('option','title','Confirm !');
	$('#konfirm1').dialog('option','buttons',{"OK" : function(){
	$('#konfirm1').dialog('close');
			$(form).ajaxSubmit({
			type : 'POST',
			url : '<?php echo base_url(); ?>calon_manager/update_breakdown/'+strkode_dealer+'/'+strkode_upline+'/'+id_unit+'/'+unit_baru,
			data: $(this).formSerialize(),
			success : function(data) {
				$("#informasi").html('');
				$("#informasi").html("BreakDown <font color='red'><b>Success</b></font>");
				$('#informasi').dialog('option','width',450);
				$('#informasi').dialog('option','title','Confirm');
				$('#informasi').dialog('option','buttons',{"OK" : function(){
				$('#informasi').dialog('close');
				location.href='<?php echo base_url(); ?>/calon_manager/breakdown';
					}
				}).dialog('open').css('text-align','center');

			}
			});
	},"Cancel" : function()
			{
				$('#konfirm1').dialog('close');
			}
	}).dialog('open').css('text-align','center');
	
    }
</script>

</div>

<div id="page">
    <div id="page-bgtop">
        <div id="content">
            <div class="post">  <h2 class="title">BREAKDOWN MANAGER</h2>

                <form method="post" id="sr_from">
                    <table width="95%" border="0" cellpadding="0" cellspacing="0" id="data" align="center">
                        <tr>
                            <td  align='left' style='width:25%' >Pilih Unit</td>
                            <td><input type="text" name="textfield4" id="intid_unit" size="30" /><div id="result2"></div></td>
                        </tr>
                        <tr>
                            <td  align='left' style='width:25%' >Cari Nama Dealer</td>
                            <td><input type="text" name="strnama_dealer" id="strnama_dealer" size="60"/></td>
                        </tr>
                        <tr>
                            <td>&nbsp;No Kartu<br /><br />&nbsp;Upline :</td>
                            <td valign="top">&nbsp;<div id="result"></div></td>
                        </tr>
                        <tr>
                            <td>&nbsp;</td>
                        </tr>
                        <tr>
                            <td>Masukan Unit Baru : </td>
                            <td><input type="text" name="unit_baru" id="unit_baru" size="60"/></td>
                        </tr>
                        <tr>
                            <td><?php //echo '<br />'.form_submit('submit','Proses','id="submit" class="button" onclick="breakdown()"')?>
                            <input type="button" onclick="breakdown();" value="Proses" id="saving2">
                            </td>
                        </tr>
                    </table>
                </form>
                
                <div id="message"></div>
                
            </div>
        </div>

    </div>
    <!-- end #content -->
    <?php $this->load->view('admin_views/sidebar_manager'); ?><!-- end #sidebar -->
    <div style="clear: both;">&nbsp;</div>
</div>

<!-- end #page -->
<div id="footer-bgcontent">
    <?php $this->load->view('admin_views/footer'); ?></div>
<!-- end #footer -->
<div id="konfirm1"></div>
<div id="informasi"></div>
